/*************************************************************************/
/** Copyright.															**/
/** FileName: Notice.c													**/
/** Author: Polarix														**/
/** Description: HMI demo for notice box interface.						**/
/*************************************************************************/
//=======================================================================//
//= Include files.													    =//
//=======================================================================//
#include "app_gui.h"
#include "SGUI_Notice.h"
#include "SGUI_FontResource.h"

//=======================================================================//
//= User Macro definition.											    =//
//=======================================================================//
#define					NOTICE_TEXT_BUFFER_SIZE				(64)

//=======================================================================//
//= Static function declaration.									    =//
//=======================================================================//
static HMI_ENGINE_RESULT	HMI_OpenDoor_Initialize(SGUI_SCR_DEV* pstDeviceIF);
static HMI_ENGINE_RESULT	HMI_OpenDoor_Prepare(SGUI_SCR_DEV* pstDeviceIF, const void* pstParameters);
static HMI_ENGINE_RESULT	HMI_OpenDoor_RefreshScreen(SGUI_SCR_DEV* pstDeviceIF, const void* pstParameters);
static HMI_ENGINE_RESULT	HMI_OpenDoor_ProcessEvent(SGUI_SCR_DEV* pstDeviceIF, const HMI_EVENT_BASE* pstEvent, SGUI_INT* piActionID);
static HMI_ENGINE_RESULT	HMI_OpenDoor_PostProcess(SGUI_SCR_DEV* pstDeviceIF, HMI_ENGINE_RESULT eProcResult, SGUI_INT iActionID);

//=======================================================================//
//= Static variable declaration.									    =//
//=======================================================================//
static SGUI_NOTICT_BOX	s_stOpenDoorBox =				{0x00};
static SGUI_CHAR		s_szOpenDoorText[NOTICE_TEXT_BUFFER_SIZE+1] = {0x00};

HMI_SCREEN_ACTION		s_stOpenDoorActions =			{	HMI_OpenDoor_Initialize,
															HMI_OpenDoor_Prepare,
															HMI_OpenDoor_RefreshScreen,
															HMI_OpenDoor_ProcessEvent,
															HMI_OpenDoor_PostProcess,
														};

//=======================================================================//
//= Global variable declaration.									    =//
//=======================================================================//
HMI_SCREEN_OBJECT       g_stHMI_OpenDoor =			{	HMI_SCREEN_ID_OPENDOOR,
															&s_stOpenDoorActions
														};

//=======================================================================//
//= Function define.										            =//
//=======================================================================//
HMI_ENGINE_RESULT HMI_OpenDoor_Initialize(SGUI_SCR_DEV* pstDeviceIF)
{
	SGUI_SystemIF_MemorySet(s_szOpenDoorText, 0x00, sizeof(SGUI_CHAR)*(NOTICE_TEXT_BUFFER_SIZE+1));
	s_stOpenDoorBox.cszNoticeText = s_szOpenDoorText;
	s_stOpenDoorBox.pstIcon = NULL;
	SGUI_Notice_FitArea(pstDeviceIF, &(s_stOpenDoorBox.stLayout));
	return HMI_RET_NORMAL;
}

HMI_ENGINE_RESULT HMI_OpenDoor_Prepare(SGUI_SCR_DEV* pstDeviceIF, const void* pstParameters)
{
	/*----------------------------------*/
	/* Process							*/
	/*----------------------------------*/
	if(NULL == pstParameters)
	{
		SGUI_SystemIF_StringLengthCopy(s_szOpenDoorText, SCR5_TITLE, NOTICE_TEXT_BUFFER_SIZE);
	    OnBoard_SendMsg(halTaskID, BKL_CTL, BKL_CLOSE, NULL);
	    BLK_State_Set(BLK_STATE_CLOSE_DOOR);
	}
	else
	{
        SGUI_SystemIF_StringLengthCopy(s_szOpenDoorText, SCR3_TITLE, sizeof(SCR3_TITLE)-1);

		SGUI_SystemIF_StringLengthCopy(s_szOpenDoorText+sizeof(SCR3_TITLE)-1,
		        (SGUI_SZSTR)pstParameters, 20);
		s_szOpenDoorText[NOTICE_TEXT_BUFFER_SIZE] = '\0';
	    OnBoard_SendMsg(halTaskID, BKL_CTL, BKL_OPEN, NULL);
	    BLK_State_Set(BLK_STATE_OPEN_DOOR);
	}
	SGUI_Notice_Repaint(pstDeviceIF, &s_stOpenDoorBox, &GB2312_FZXS12, 0);
	OnBoard_SendTime(halTaskID, TIME_CD, CMD_ON, 2800);
	return HMI_RET_NORMAL;
}

HMI_ENGINE_RESULT HMI_OpenDoor_RefreshScreen(SGUI_SCR_DEV* pstDeviceIF, const void* pstParameters)
{
	SGUI_Notice_Repaint(pstDeviceIF, &s_stOpenDoorBox, &GB2312_FZXS12, 0);
	return HMI_RET_NORMAL;
}

HMI_ENGINE_RESULT HMI_OpenDoor_ProcessEvent(SGUI_SCR_DEV* pstDeviceIF, const HMI_EVENT_BASE* pstEvent, SGUI_INT* piActionID)
{
	/*----------------------------------*/
	/* Variable Declaration				*/
	/*----------------------------------*/
	HMI_ENGINE_RESULT           eProcessResult;
	SGUI_UINT16					uiKeyValue;
	KEY_PRESS_EVENT*			pstKeyEvent;
	SGUI_INT					iProcessAction;

	/*----------------------------------*/
	/* Initialize						*/
	/*----------------------------------*/
	eProcessResult =			HMI_RET_NORMAL;
	iProcessAction =			HMI_DEMO_PROC_NO_ACT;

	/*----------------------------------*/
	/* Process							*/
	/*----------------------------------*/
	if(EVENT_TYPE_ACTION == pstEvent->iType)
	{
		if(EVENT_ID_KEY_PRESS == pstEvent->iID)
		{
			pstKeyEvent = (KEY_PRESS_EVENT*)pstEvent;
			uiKeyValue = KEY_CODE_VALUE(pstKeyEvent->Data.uiKeyValue);

//			switch(uiKeyValue)
//			{
//				case KEY_NUMP:
//					iProcessAction = HMI_DEMO_PROC_CANCEL;
//					break;
//			}
		}
		else if(EVENT_ID_TIMER == pstEvent->iID)
		{
//		    HMI_SwitchScreen(HMI_SCREEN_ID_STANDBY,NULL);
		    HMI_GoBack(NULL);
		}
	}
	if(NULL != piActionID)
	{
		*piActionID = iProcessAction;
	}

	return eProcessResult;
}

HMI_ENGINE_RESULT HMI_OpenDoor_PostProcess(SGUI_SCR_DEV* pstDeviceIF, HMI_ENGINE_RESULT eProcResult, SGUI_INT iActionID)
{
	/*----------------------------------*/
	/* Process							*/
	/*----------------------------------*/
	if(HMI_PROCESS_SUCCESSFUL(eProcResult))
	{
		if(HMI_DEMO_PROC_CANCEL == iActionID)
		{
//			HMI_GoBack(NULL);
		}
	}
	return HMI_RET_NORMAL;
}

